﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace BBPA.API
{
    /// <summary>
    /// SMS 的摘要说明
    /// </summary>
    public class SMS : IHttpHandler
    {
        BLL.SMS bllSMS = new BLL.SMS();
        public void ProcessRequest(HttpContext context)
        {
            CallBak<List<Model.SMS>> callBak = new CallBak<List<Model.SMS>>();
            MyHttpContent cont = new MyHttpContent(context);
            //读取request
            int SMSID = cont.rqInt("SMSID"), State = cont.rqInt("State");
            //
            if (SMSID == 0)
            {//获取为发送列表
                string sql_where="State="+(int)EnumHelper.SendSMSstate.Wait;
                callBak.Set(bllSMS.GetModelList(sql_where+" order by dateandtime "));
                foreach (Model.SMS sms in callBak.ReturnVal)
                {
                    sms.State = (int)EnumHelper.SendSMSstate.Sending;
                    bllSMS.Update(sms);
                }
            }
            else
            {//更新发送状态
                Model.SMS modelSMS = bllSMS.GetModel(DataTypePlus.requestInt(SMSID));
                modelSMS.State = DataTypePlus.requestInt(State);
                bllSMS.Update(modelSMS);
            }
            
            context.Response.ContentType = "text/javascript";
            context.Response.Write(cont.rq("callback") + "(" + StringPlus.Object2Json4Js(callBak) + ")");
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}